
#include "GraphGdi.h"


int CGraphGdi::Draw_Text(char *text, int x,int y,COLORREF color)
{
	// this function draws the sent text on the sent surface 
	// using color index as the color in the palette

	HDC xdc; // the working dc

	// get the dc from surface
	if (FAILED(m_pBackSurface->GetDC(&xdc)))
		return -1;

	// set the colors for the text up
	SetTextColor(xdc,color);

	// set background mode to transparent so black isn't copied
	SetBkMode(xdc, TRANSPARENT);

	// draw the text a
	TextOut(xdc,x,y,text,strlen(text));

	// release the dc
	m_pBackSurface->ReleaseDC(xdc);

	// return success
	return 0;
} // end Draw_Text_GDI

///////////////////////////////////////////////////////////

int CGraphGdi::Draw_Text(char *text, int x,int y,int color)
{
	// this function draws the sent text on the sent surface 
	// using color index as the color in the palette

	HDC xdc; // the working dc

	// get the dc from surface
	if (FAILED(m_pBackSurface->GetDC(&xdc)))
		return -1;

	PPALETTEENTRY	palette = m_pDDraw->GetPalette(color);

	// set the colors for the text up
	SetTextColor(xdc,RGB(palette->peRed,palette->peGreen,palette->peBlue) );

	// set background mode to transparent so black isn't copied
	SetBkMode(xdc, TRANSPARENT);

	// draw the text a
	TextOut(xdc,x,y,text,strlen(text));

	// release the dc
	m_pBackSurface->ReleaseDC(xdc);

	// return success
	return 0;
} // end Draw_Text_GDI

int CGraphGdi::Draw_Rectangle(int x1, int y1, int x2, int y2, int color)
{
	// this function uses directdraw to draw a filled rectangle

	DDBLTFX ddbltfx; // this contains the DDBLTFX structure
	RECT fill_area;  // this contains the destination rectangle

	// clear out the structure and set the size field 
	DDRAW_INIT_STRUCT(ddbltfx);

	// set the dwfillcolor field to the desired color
	ddbltfx.dwFillColor = color; 

	// fill in the destination rectangle data (your data)
	fill_area.top    = y1;
	fill_area.left   = x1;
	fill_area.bottom = y2;
	fill_area.right  = x2;

	// ready to blt to surface, in this case blt to primary
	m_pBackSurface->Blt(&fill_area, // ptr to dest rectangle
		NULL,       // ptr to source surface, NA            
		NULL,       // ptr to source rectangle, NA
		DDBLT_COLORFILL | DDBLT_WAIT,   // fill and wait                   
		&ddbltfx);  // ptr to DDBLTFX structure

	// return success
	return 0;

} // end Draw_Rectangle